<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../header.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
	.main_div{
		margin : 15px;
	}
</style>
</head>
<body>
  	<div class="main_div">
		<form id="formId"  class="layui-form layui-form-pane" action="">
			<div class="layui-form-item">
				<label class="layui-form-label">商品名</label>
				<div class="layui-input-block">
					<input type="text" name="name" autocomplete="off" placeholder="请输入商品名" class="layui-input">
				</div>
				<%--</div>
                <div class="layui-form-item">
                  <label class="layui-form-label">商品副标题</label>
                  <div class="layui-input-block">
                    <input type="text" name="subtitle" lay-verify="required" placeholder="请输入商品副标题" autocomplete="off" class="layui-input">
                  </div>--%>
			</div>

			<%--<div class="layui-form-item">
              <label class="layui-form-label">青选择分类</label>
              <div class="layui-input-inline">
                <select lay-filter="filter">
                  <option value="">请选择一级分类</option>
                  <c:forEach items="${topCategoryList}" var="category">
                      <option value="${category.id}" >${category.name}</option>
                  </c:forEach>
                </select>
              </div>
              <div class="layui-input-inline">
                <select id="categoryId" name="categoryId">
                  <option value="">请选择市</option>

                </select>
              </div>
            </div>--%>
			<div class="layui-form-item">
				<label class="layui-form-label">商品单位</label>
				<div class="layui-input-block">
					<input type="text" name="unit" lay-verify="required" placeholder="请输入商品单位" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">商品价格</label>
				<div class="layui-input-block">
					<input type="text" name="price" lay-verify="required" placeholder="请输入商品价格" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">商品数量</label>
				<div class="layui-input-block">
					<input type="text" name="stock" lay-verify="required" placeholder="请输入商品数量" autocomplete="off" class="layui-input">
				</div>
			</div>

			<%-- <div class="layui-form-item" pane="">
               <label class="layui-form-label">商品状态</label>
               <div class="layui-input-block">
                 <input type="radio" name="status" value="1" title="在售" checked="">
                 <input type="radio" name="status" value="2" title="下架">
                 <input type="radio" name="status" value="3" title="删除">
               </div>
             </div>--%>

			<div class="layui-form-item" pane="">
				<label class="layui-form-label">图片上传</label>
				<div class="layui-upload layui-input-inline">
					<div class="layui-upload-list">
						<input type="hidden" name="image"/>
						<img class="layui-upload-img" width="150px" height="150px" id="image">
						<p id="demoText"></p>
					</div>
					<button type="button" class="layui-btn" id="uploadImage">上传图片</button>
				</div>
			</div>
			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label">商品详情</label>
				<div class="layui-input-block">
					<textarea id="detailId" placeholder="请输入内容" name="detail" class="layui-textarea"></textarea>
				</div>
			</div>
			<div class="layui-form-item">
				<input class="layui-btn" type="button" onclick="submitForm()" value="保存"/>
			</div>
		</form>
	</div>

	<script src="${path}/static/kindeditor/kindeditor.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
	 	layui.config({
			base : '${path}/static/'
		  }).extend({
		    selectM: './layui_extends/selectM'
		  }).use(['form','upload','selectM'],function(){
		  	var form = layui.form;
		  	var upload = layui.upload;
		  	var selectM = layui.selectM;
		  	
		  	$.ajax({
				url : '${path}/user/selectUserAndRoles',
				type : 'POST',
				data : {"userId" : "${param.userId}"},
				dataType : 'json',
				success : function(jsonResult) {
					if(jsonResult.ok) {
						var user = jsonResult.data["user"];
						var allRoles = jsonResult.data["allRoles"];
						var selectIds = jsonResult.data["selectIds"];
						$("#id").val(user.id);
						$("#name").val(user.name);
						$("#trueName").val(user.trueName);
						$("#email").val(user.email);
						$("#phone").val(user.phone);
						$("#password").val(user.password);
						
						 //多选标签-基本配置
					    var tagIns = selectM({
					      //元素容器【必填】
					      elem: '#roles'
					      //候选数据【必填】
					      ,data: allRoles
					      //默认值
					      ,selected: selectIds
					   	  // 默认最多选中5个
					      ,max : 100
					    });
					}
				}
			});
		});
		
		//ajax方式提交form表单
		function submitForm(){
			$.ajax({
				url : '${path}/product/update',
				data : $('#form_add').serialize(),
				type : 'POST',
				dataType : 'json',
				success : function(jsonResult) {
					if(jsonResult.ok) {
						//mylayer.success(jsonResult.msg);
						mylayer.confirm("保存成功，是否跳转到商品管理界面？", "${path}/product/getProductPage");
					} else {
						mylayer.errorMsg(jsonResult.msg);
					}
				}
			});
		}
		KindEditor.ready(function(K) {
			var kingEditorParams = {
				afterBlur: function () { this.sync(); }
			}
			KindEditor.create('#detailId', kingEditorParams);
		});
		
	</script>
</body>
</html>